package com.omega.encryptedsql.utils;

/**
 * @author omega
 * @description: TODO
 * @date 2025/7/10
 */
import java.nio.charset.StandardCharsets;

public class KeyValidateUtil {

    public static void validateAesKey(String key) {
        if (key == null) {
            throw new IllegalArgumentException("AES key cannot be null");
        }

        byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
        int length = keyBytes.length;

        System.out.println("Key: " + key);
        System.out.println("Key length (bytes): " + length);
        System.out.println("Key length (bits): " + (length * 8));

        if (length != 16 && length != 24 && length != 32) {
            System.out.println(
                    "Invalid AES key length: " + length * 8 + " bits. " +
                            "Key must be 128, 192 or 256 bits (16, 24 or 32 bytes).\n" +
                            "Provided key: " + key
            );
        }
    }

    public static void main(String[] args) {
        // 测试密钥
        validateAesKey("SzjMf3+47sz9gMXV9US+4w==");
        validateAesKey("W7wuoHl$(Cn)*XR2Zx6Lc4IghOSW0^u0");
        validateAesKey("rg4cfa/tPXEE7R4c3CzCRQ==");
    }
}